﻿@{
    Layout = null;
}

@* 引用命名空间 *@
@using MVCProject.Model;

@* 强制页面类型 *@
@model Users

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    @Styles.Render("~/layui/css")
    @Scripts.Render("~/bundles/modernizr")
</head>
<body>

    @{
        List<SelectListItem> rolelist = new List<SelectListItem>();

        foreach (var role in ViewBag.roles as List<MVCProject.Model.Roles>)
        {
            rolelist.Add(
                new SelectListItem()
                { Text = role.roleName, Value = role.roleID + "" });
        }
    }

    <div class="layui-container" style="margin-top:40px;">

        @using (@Ajax.BeginForm("Edit", "Users", new AjaxOptions()
        {
            HttpMethod = "POST",
            OnSuccess = "MySuccess"
        }, new { @class = "layui-form" }))
        {
            @Html.TextBoxFor(u => u.userID, new { type = "hidden" })
            <input type="hidden" name="UserID" />
            <div class="layui-form-item">
                <label class="layui-form-label">出生日期</label>
                <div class="layui-input-inline">
                    <input id="mybirthday" type="text" name="Birthday" class="layui-input" value="@Model.birthday">
                </div>
            </div>
            @*<div class="layui-form-item">
                <label class="layui-form-label">部门</label>
                <div class="layui-input-inline">
                    <select name="DeptID" lay-verify="required" lay-filter="myDeptSelect" value="@Model.Roles.deptID">
                    </select>
                </div>
            </div>*@
            <div class="layui-form-item">
                <label class="layui-form-label">角色</label>
                <div class="layui-input-inline">
                    @Html.DropDownListFor(u => u.roleID, rolelist)
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="Name" value="@Model.name" required lay-verify="required|username" placeholder="请输入标题" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                    <input type="radio" name="Sex" value="男" title="男">
                    <input type="radio" name="Sex" value="女" title="女" checked>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">手机</label>
                <div class="layui-input-block">
                    <input type="text" name="Phone" value="@Model.phone" required lay-verify="required|phone" placeholder="请输入标题" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="Pwd" value="@Model.pwd" required lay-verify="required|pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">登录密码</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="Status" value="true" lay-filter="myStatus" lay-skin="switch" lay-text="正常|冻结" checked>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        }

    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/layui")
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/jqueryuno")

    <script type="text/javascript">

        var form;
        layui.use(['form', 'laydate'], function () {
            form = layui.form;
            var laydate = layui.laydate;
            //执行一个laydate实例
            laydate.render({
                elem: '#mybirthday' //指定元素
                //参数即为：2018-08-20 20:08:08 的时间戳
            });
        });

        function MySuccess(res) {
            console.log(res);
            if (res.code > 0) {
                //调用父窗口关闭弹窗
                top.layer.closeAll();
                //在父窗口中提示消息
                top.layer.msg(res.msg, { icon: 6 });
                //刷新父窗口中的列表数据
                //这里以搜索为例
                top.tableIns.reload({
                    where: { //设定异步数据接口的额外参数，任意设
                        name: $('#txt_search').val()
                        //…
                    }
                });
            } else (res == 0)

        }
    </script>

</body>
</html>
